using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.DAL;
using System.Data.SqlClient;
using System.Data;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblNewsExtended : TblNews
    {
        public static CustomCollection<TblNews> GetActiveNewsByCount(int howMany)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@howMany", SqlDbType.Int, 0, ParameterDirection.Input, howMany);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_ACTIVE_NEWS_BY_COUNT);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblNewsCollectionFromReader);
            CustomCollection<TblNews> objCollection = ((CustomCollection<TblNews>)ExecuteReaderCmd(sqlCmd, reader));
            return objCollection;
        }

        public static int GetActiveNewsCount()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_ACTIVE_NEWS_COUNT);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblNews> GetNonDeletedNewsPaged(string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_NONDELETED_NEWS_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblNewsCollectionFromReader);
            CustomCollection<TblNews> objCollection = ((CustomCollection<TblNews>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetNonDeletedNewsCount()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_NONDELETED_NEWS_COUNT);

            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblNews> GetAllNewsByNewsNamePaged(string newsName, string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@newsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, newsName);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_ALL_NEWS_BY_NAME_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblNewsCollectionFromReader);
            CustomCollection<TblNews> objCollection = ((CustomCollection<TblNews>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetAllNewsByNewsNameCount(string newsName)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@newsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, newsName);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_ALL_NEWS_BY_NAME_COUNT);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static CustomCollection<TblNews> GetNonDeletedNewsByNewsNamePaged(string newsName, string orderBy, int startRow, int pageSize)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@newsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, newsName);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_NONDELETED_NEWS_BY_NAME_PAGED);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblNewsCollectionFromReader);
            CustomCollection<TblNews> objCollection = ((CustomCollection<TblNews>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        public static int GetNonDeletedNewsByNewsNameCount(string newsName)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@newsName", SqlDbType.NVarChar, 500, ParameterDirection.Input, newsName);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWS_GET_NONDELETED_NEWS_BY_NAME_COUNT);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        private const string SP_TBL_NEWS_GET_ACTIVE_NEWS_BY_COUNT = "sp_TblNews_Get_Active_News_By_Count";
        private const string SP_TBL_NEWS_GET_ACTIVE_NEWS_COUNT = "sp_TblNews_Get_Active_News_Count";
        private const string SP_TBL_NEWS_GET_NONDELETED_NEWS_PAGED = "sp_TblNews_Get_NonDeleted_News_Paged";
        private const string SP_TBL_NEWS_GET_NONDELETED_NEWS_COUNT = "sp_TblNews_Get_NonDeleted_News_Count";
        private const string SP_TBL_NEWS_GET_ALL_NEWS_BY_NAME_PAGED = "sp_TblNews_Get_All_News_By_Name_Paged";
        private const string SP_TBL_NEWS_GET_ALL_NEWS_BY_NAME_COUNT = "sp_TblNews_Get_All_News_By_Name_Count";
        private const string SP_TBL_NEWS_GET_NONDELETED_NEWS_BY_NAME_PAGED = "sp_TblNews_Get_NonDeleted_News_By_Name_Paged";
        private const string SP_TBL_NEWS_GET_NONDELETED_NEWS_BY_NAME_COUNT = "sp_TblNews_Get_NonDeleted_News_By_Name_Count";

    }
}
